#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import os
import sys

execfile(os.path.join(sys.path[0], "framework.py"))

from oriolus.pith.packets.hashbuilder import HashBuilder
from oriolus.pith.packets.hashwriter import Strategy, Visitor
from unittest import TestCase, TestLoader, TextTestRunner

class TestStrategy(TestCase):

    def setUp(self):
        content = "somedata"
        expected_hash_adapter = HashBuilder("md5")

        self.__expected_hash = expected_hash_adapter.get_hash(content)
        self.__file_name = "mock_file"  
        
        fd = file(self.__file_name, "w")
        fd.write(content)
        fd.close()

    def tearDown(self):
        os.remove( self.__file_name)

    def test_strategy1(self):
        dict = {}
        strategy = Strategy()
        dict[self.__file_name] = strategy.get_file_hash(self.__file_name)

        self.assertEqual(self.__expected_hash, dict[ self.__file_name])

if __name__ == "__main__":
    suite = TestLoader().loadTestsFromTestCase(TestStrategy)
    TextTestRunner(verbosity=2).run(suite)
